﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for GProductBLL
/// </summary>
public class GProductBLL
{
    public static List<GProduct> GetProductsByDate(DateTime dtStart, DateTime dtEnd)
    {
        DSGProductTableAdapters.GProductDSTableAdapter tableadapter = new DSGProductTableAdapters.GProductDSTableAdapter();
        List<GProduct> listProducts = new List<GProduct>();
        if (dtStart != null && dtEnd != null)
        {
            DSGProduct.GProductDSDataTable datatable = tableadapter.GetGProductBySaleDate(dtStart, dtEnd);
            foreach (DSGProduct.GProductDSRow row in datatable)
            {
                listProducts.Add(RowToDTO(row));
            }
        }
        return listProducts;
    }

    public static List<GProduct> GetProductsByDate(DateTime dtStart, DateTime dtEnd, int ClienteID)
    {
        DSGProductTableAdapters.GProductDSTableAdapter tableadapter = new DSGProductTableAdapters.GProductDSTableAdapter();
        List<GProduct> listProducts = new List<GProduct>();
        if (dtStart != null && dtEnd != null && ClienteID > 0)
        {
            DSGProduct.GProductDSDataTable datatable = tableadapter.GetGProductBySaleDateClient(dtStart, dtEnd, ClienteID);
            foreach (DSGProduct.GProductDSRow row in datatable)
            {
                listProducts.Add(RowToDTO(row));
            }
        }
        return listProducts;
    }

    public static List<GProduct> GetVentasByRange(DateTime dtStart, DateTime dtEnd)
    {
        DSGVentaTableAdapters.GVentaDSTableAdapter adapter = new DSGVentaTableAdapters.GVentaDSTableAdapter();

        List<GProduct> listProducts = new List<GProduct>();
        if (dtStart != null && dtEnd != null)
        {
            DSGVenta.GVentaDSDataTable datatable = adapter.GetVentasByRange(dtStart, dtEnd);
            foreach (DSGVenta.GVentaDSRow row in datatable)
            {
                listProducts.Add(RowToDTOVenta(row));
            }
        }
        return listProducts;
    }

    public static List<GProduct> GetVentasByRange(DateTime dtStart, DateTime dtEnd, int Cliente_id)
    {
        DSGVentaTableAdapters.GVentaDSTableAdapter adapter = new DSGVentaTableAdapters.GVentaDSTableAdapter();

        List<GProduct> listProducts = new List<GProduct>();
        if (dtStart != null && dtEnd != null && Cliente_id > 0)
        {
            DSGVenta.GVentaDSDataTable datatable = adapter.GetVentasByRangeCliente(dtStart, dtEnd, Cliente_id);
            foreach (DSGVenta.GVentaDSRow row in datatable)
            {
                listProducts.Add(RowToDTOVenta(row));
            }
        }
        return listProducts;
    }

    public static GProduct RowToDTO(DSGProduct.GProductDSRow row)
    {
        if (row != null)
            return new GProduct(row.iProducto_id, row.sProducto_nm, "", row.sumatotal);
        return new GProduct();
    }

    public static GProduct RowToDTOVenta(DSGVenta.GVentaDSRow row)
    {
        if (row != null)
            return new GProduct(0, row.sFecha_dt.ToString("d"), "", row.sumatotal);
        return new GProduct();
    }
}